using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TpPoint : MonoBehaviour
{
    [SerializeField] private GameObject endPoint;
    [SerializeField] private OffsetSide offsetSide;
    [SerializeField] private GameObject PanelEffect;
     private GameObject MainCamera;

    private Animator animPanel;
    public enum NameNextLocations{Main = 0, Forest = 1, BitchBeach = 2, Hotel = 3, House = 4, Secret = 5, Room_4 = 6}
    [SerializeField] NameNextLocations NameNextLocation;
    
    private void Start()
    {
      
        animPanel = PanelEffect.GetComponent<Animator>();
        MainCamera = GameObject.FindGameObjectWithTag("MainCamera");
        
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.CompareTag("Player"))
        {
            StartCoroutine(TpGG(collision));
            
        }
    }

    private IEnumerator TpGG(Collider2D collision)
    {
       // PlayerData.Player.OnCanInteractive(false);
        collision.GetComponent<PlayerController>().OnCanInteractive(false);
        PanelEffect.SetActive(true);
        animPanel.SetTrigger("transition");
        yield return new WaitForSeconds(0.7f);
        OffsetSide s = endPoint.GetComponent<TpPoint>().offsetSide;
        Vector2 v = endPoint.transform.position;
        Vector2 sizeTrigger = endPoint.GetComponent<BoxCollider2D>().size;
        MainCamera.GetComponent<CameraController>().CahngeLimet(NameNextLocation);
        switch (s)
        {
            case OffsetSide.Left: collision.gameObject.transform.position = new Vector2(v.x - sizeTrigger.x, v.y); break;
            case OffsetSide.Right: collision.gameObject.transform.position = new Vector2(v.x + sizeTrigger.x, v.y); break;
            case OffsetSide.Botton: collision.gameObject.transform.position = new Vector2(v.x, v.y - sizeTrigger.y + 0.5f); break;
            case OffsetSide.Up: collision.gameObject.transform.position = new Vector2(v.x, v.y + sizeTrigger.y + 0.3f); break;
        }
        yield return new WaitForSeconds(1.0f);
        PanelEffect.SetActive(false);
//        PlayerData.Player.OnCanInteractive(true);
    collision.GetComponent<PlayerController>().OnCanInteractive(true);
    }

    private enum OffsetSide
    { 
        Left,
        Right,
        Botton,
        Up
    }
    

}
